﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;

namespace WebUI.Services
{
    public class SettingsInitializer
    {
        public static void InitSettings()
        {
            System.Reflection.FieldInfo fi = null;
            fi = typeof(System.Configuration.ConfigurationElement).GetField("_bReadOnly", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            
            var flag = System.Configuration.ConfigurationManager.ConnectionStrings["ConnFlag"].ConnectionString;
            foreach (System.Configuration.ConnectionStringSettings item in System.Configuration.ConfigurationManager.ConnectionStrings)
            {
                fi.SetValue(item, false);

                item.ConnectionString = string.Format(item.ConnectionString,
                    WebUI.OtherSettings.Values[flag+"/user"],
                    WebUI.OtherSettings.Values[flag+"/pwd"]);
            }
        }
    }
}